package com.example.mymvvmdemo.models.add_article.adapter;

import android.content.Context;

import com.example.mymvvmdemo.base.BaseVBAdapter;
import com.example.mymvvmdemo.databinding.ItemBlogTagBinding;
import com.example.mymvvmdemo.models.add_article.entity.BlogCategoriesEntity;
import com.example.mymvvmdemo.models.add_article.entity.BlogTagEntity;
import com.example.mymvvmdemo.utils.StrUtils;

import java.util.ArrayList;

public class BlogCategoriesAdapter extends BaseVBAdapter<BlogCategoriesEntity.DataDTO, ItemBlogTagBinding> {

    public CategoriesListener listener;

    public void setListener(CategoriesListener listener) {
        this.listener = listener;
    }

    /**
     * @param context
     */
    public BlogCategoriesAdapter(Context context, ArrayList<BlogCategoriesEntity.DataDTO> list) {
        super(context);
        setDataList(list);
    }

    @Override
    protected void updateData(ItemBlogTagBinding bind, BlogCategoriesEntity.DataDTO item, int position) {

        String name = item.getName();
        if(!StrUtils.isEmpty(name)){
            bind.tvTag.setText(name);
        }

        boolean select = item.isSelect();
        bind.tvTag.setAlpha(select ? 1.0f : 0.5f);

        bind.tvTag.setOnClickListener(view -> {
            if (listener != null) {
                listener.onClickCategories(position);
            }
        });

    }


    public interface CategoriesListener {
        void onClickCategories(int position);
    }

}
